package cn.zhonghuanzhiyuan.sprc.basicinfo.controller;

import cn.org.bachelor.web.json.JsonResponse;

import cn.zhonghuanzhiyuan.sprc.basicinfo.domain.SafeDeviceStopStart;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.*;
import cn.zhonghuanzhiyuan.sprc.basicinfo.service.SafeDeviceStopStartService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 装置停开车(SafeDeviceStopStart)控制层
 *
 * @author david
 * @since 2024-02-27 21:19:28
 */
@Api(tags = "装置停开车控制层")
@RestController
@RequestMapping("/safeDeviceStopStart")
@CrossOrigin // 线上不需要 （要注掉）
public class SafeDeviceStopStartController {
    /**
     * 服务对象
     */
    @Autowired
    private SafeDeviceStopStartService safeDeviceStopStartService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "获取装置停开车单条数据")
    @GetMapping("/getSafeDeviceStopStartById/{id}")
    public HttpEntity<JsonResponse> getSafeDeviceStopStartById(@ApiParam(name = "id", value = "编号", required = true) @PathVariable String id) {
        SafeDeviceStopStart safeDeviceStopStart = safeDeviceStopStartService.getSafeDeviceStopStartById(id);
        return JsonResponse.createHttpEntity(safeDeviceStopStart, HttpStatus.OK);
    }

    /**
     * 分页查询
     *
     * @param querySafeDeviceStopStartVo
     * @return PageInfo<SafeDeviceStopStart>
     */
    @ApiOperation(value = "获取装置停开车分页数据")
    @PostMapping("/getSafeDeviceStopStartPage")
    public HttpEntity<JsonResponse> getSafeDeviceStopStartPage(@ApiParam(name = "querySafeDeviceStopStartVo", value = "装置停开车", required = true) @RequestBody QuerySafeDeviceStopStartVo querySafeDeviceStopStartVo) {
        PageHelper.startPage(querySafeDeviceStopStartVo.getPageNum(), querySafeDeviceStopStartVo.getPageSize());
        List<SafeDeviceStopStart> list = safeDeviceStopStartService.selectSafeDeviceStopStartList(querySafeDeviceStopStartVo);
        return JsonResponse.createHttpEntity(new PageInfo<>(list), HttpStatus.OK);
    }

    /**
     * 导出查询
     *
     * @param querySafeDeviceStopStartVo
     * @return SafeDeviceStopStart
     */
    @ApiOperation(value = "获取装置停开车导出数据")
    @PostMapping("/getSafeDeviceStopStartList")
    public HttpEntity<JsonResponse> getSafeDeviceStopStartList(@ApiParam(name = "querySafeDeviceStopStartVo", value = "装置停开车", required = true) @RequestBody QuerySafeDeviceStopStartVo querySafeDeviceStopStartVo) {
        List<SafeDeviceStopStart> list = safeDeviceStopStartService.selectSafeDeviceStopStartList(querySafeDeviceStopStartVo);
        return JsonResponse.createHttpEntity(list, HttpStatus.OK);
    }

    /**
     * 新增或保存
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改或新增装置停开车")
    @PostMapping("/updateOrSaveSafeDeviceStopStart")
    public HttpEntity<JsonResponse> updateOrSaveSafeDeviceStopStart(@ApiParam(name = "updateOrSaveSafeDeviceStopStartVo", value = "装置停开车", required = true) @RequestBody UpdateOrSaveSafeDeviceStopStartVo updateOrSaveSafeDeviceStopStartVo) {
        safeDeviceStopStartService.insertOrUpdate(updateOrSaveSafeDeviceStopStartVo);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除装置停开车")
    @DeleteMapping("/deleteSafeDeviceStopStartByIds/{ids}")
    public HttpEntity<JsonResponse> deleteSafeDeviceStopStartByIds(@ApiParam(name = "idList", value = "主键集合", required = true) @PathVariable String ids) {
        safeDeviceStopStartService.deleteByIds(ids);
        return JsonResponse.createHttpEntity(HttpStatus.OK);
    }

}
